package com.guchenbo.study.aop;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TxServiceBImpl implements TxServiceB {
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void defaultTx(boolean flag) {
        System.out.println("REQUIRED tx");
        if (flag) {
            throw new RuntimeException("random error");
        }
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void newTx(boolean flag) {
        System.out.println("REQUIRES_NEW tx");
        if (flag) {
            throw new RuntimeException("random error");
        }
    }

    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void nestTx(boolean flag) {
        System.out.println("NESTED tx");
        if (flag) {
            throw new RuntimeException("random error");
        }
    }
}
